<?php
namespace app\api\controller;
use think\Controller;
use think\Loader;
use WxpayAPPAPI\WxPayOrderQuery;
use WxpayAPPAPI\WxPayApi;

vendor('WxpayAPPAPI.WxPayJsApiPay');
vendor('WxpayAPPAPI.WxPayNotify');

/**
 * Description of Wxpay
 *
 * @author Administrator
 */
class WxpayNotifyCallBack extends \WxPayNotify
{


    //查询订单
    public function Queryorder($transaction_id)
    {
        $input = new WxPayOrderQuery();
        $input->SetTransaction_id($transaction_id);
        $result = WxPayApi::orderQuery($input);

        if (array_key_exists("return_code", $result) && array_key_exists("result_code", $result) && $result["return_code"] == "SUCCESS" && $result["result_code"] == "SUCCESS")
            return $result;

        return false;
    }

    public function NotifyProcess($data, &$msg)
    {
        if (!$queryorder = $this->Queryorder($data["transaction_id"]))
        {
            $msg = "订单查询失败";
            return false;
        }
        else
        {
            if ($queryorder['trade_state'] == "SUCCESS") {
                //file_put_contents('wxpay.txt', date('Y-m-d H:i:s') . "---------- \n " . json($data));

                // $data['attach'] 商家数据包 字符串类型   解析字符串执行对应业务操作
                if ($data['attach'] == 2) {

                }
            }
        }
        return true;
    }

}
